from fastapi import APIRouter, Depends, HTTPException, status
from services.company_service import CompanyService
from schemas.base import create_response, create_response_by_page
from schemas.company import CompanyQueryRequest
import asyncio
import traceback

router = APIRouter(prefix="/company", tags=["company"])
service = CompanyService()

@router.get("/getList")
async def get_List(params: CompanyQueryRequest = Depends()):
    # print(params)
    try:
        data = await service.get_company_list(params)
        if not data:
            response={"code": 404, "message": f"查询企业失败"}
        else:    
            response = await create_response_by_page(200, "查询成功", data["total"], data["page"], 
                                                     data["page_size"], data["total_pages"], data['data'])
        return response
    except Exception as e:
        raise HTTPException(
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
            detail={
                "code": 500,
                "message": f"企业查询失败: {str(e)}",
            }
        )